<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Sprite Animation</title>
  </head>

  <body>
    <canvas width="750" height="1000" id="canvas" style="width: 100%"></canvas>
    <script src="https://cdn.bootcdn.net/ajax/libs/pixi.js/4.8.7/pixi.min.js"></script>

    <script src="/dist/cdn/EVA.js"></script>
    <script src="/dist/cdn/EVA.rendererAdapter.js"></script>
    <script src="/dist/cdn/EVA.plugin.renderer.js"></script>
    <script src="/dist/cdn/EVA.plugin.renderer.spriteAnimation.js"></script>
    <script>
      const {Game, GameObject, resource, RESOURCE_TYPE} = EVA;
      const {RendererSystem} = EVA.plugin.renderer;
      const {SpriteAnimation, SpriteAnimationSystem} = EVA.plugin.renderer.spriteAnimation;

      resource.addResource([
        {
          name: 'fruit',
          type: RESOURCE_TYPE.SPRITE_ANIMATION,
          src: {
            image: {
              type: 'png',
              url: 'https://gw.alicdn.com/bao/uploaded/TB15pMkkrsTMeJjSszhXXcGCFXa-377-1070.png',
            },
            json: {
              type: 'json',
              url: 'https://gw.alicdn.com/mt/TB1qCvumsyYBuNkSnfoXXcWgVXa.json',
            },
          },
          preload: false,
        },
      ]);

      const game = new Game({
        systems: [
          new RendererSystem({
            canvas: document.querySelector('#canvas'),
            width: 750,
            height: 1000,
          }),
          new SpriteAnimationSystem(),
        ],
      });

      const cut = new GameObject('cut', {
        position: {x: 225, y: 400},
        size: {width: 300, height: 200},
        origin: {x: 0, y: 0},
      });

      const frame = cut.addComponent(
        new SpriteAnimation({
          resource: 'fruit',
          speed: 100,
        }),
      );

      frame.play();

      game.scene.addChild(cut);
    </script>
  </body>
</html>
